public class ManagerFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
/**
 *获取请求的URI 判断请求的页面
 */
        String uri = request.getRequestURI();
/**
 * 先放行预约和登录页面
 */
        if (uri.contains("index.jsp") || uri.contains("ManagerLogin.jsp") || uri.contains("Manager.do")){
            filterChain.doFilter(servletRequest, servletResponse);
        }

        /**
         *      如果含有这三个页面的信息  判断这个人是不是管理员
         */
        if (uri.contains("BookInfo.jsp")){
            Users user = (Users)request.getSession().getAttribute("user");
            System.out.println("当前用户:"+user);
/**
 *      有信息即是管理员 放行
 */
            if (user != null){
                filterChain.doFilter(servletRequest, servletResponse);
            }else {
                request.setAttribute("errormsg","请先获取管理员权限");
                request.getRequestDispatcher("ManagerLogin.jsp").forward(servletRequest, servletResponse);
            }

        }

    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }
}